package com.kwq.designPattern.exam;

import com.google.gson.Gson;
import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
import com.google.gson.JsonParser;
import lombok.AllArgsConstructor;
import lombok.Data;
import org.apache.commons.io.FileUtils;
import org.apache.commons.lang3.StringUtils;
import org.apache.poi.ss.usermodel.Cell;
import org.apache.poi.ss.usermodel.CellType;
import org.apache.poi.ss.usermodel.Row;
import org.apache.poi.ss.usermodel.Sheet;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;

import java.io.File;
import java.io.IOException;
import java.util.*;
import java.util.function.Predicate;
import java.util.stream.Collectors;

/**
 * @author kangwanqiang
 * @date 2021/4/15
 */
public class ArraysTest {
    public static void main(String[] args) throws IOException {
       /* 创建Excel，读取文件内容
        File file = new File("/Users/kangwanqiang/Downloads/id.xlsx");
        XSSFWorkbook workbook = new XSSFWorkbook(FileUtils.openInputStream(file));
        //两种方式读取工作表
        Sheet sheet = workbook.getSheetAt(0);
        //获取sheet中最后一行行号
        int lastRowNum = sheet.getLastRowNum();
        StringBuilder s = new StringBuilder();
        for (int i = 1; i <= lastRowNum; i++) {
            Row row = sheet.getRow(i);
            //获取当前行最后单元格列号
            int lastCellNum = row.getLastCellNum();
            for (int j = 0; j < lastCellNum; j++) {
                Cell cell = row.getCell(j);
                CellType cellType = cell.getCellType();
                Integer value = 0;
                if (cellType.equals(CellType.STRING)){
                    value= Integer.valueOf(cell.getStringCellValue());
                }else if (cellType.equals(CellType.NUMERIC)){
                    value = (int)Double.parseDouble(String.valueOf(cell.getNumericCellValue()));
                }

                s.append("'").append(value).append("'").append(",");
            }
        }
        s.setLength(s.length()-1);
        System.out.println(s);*/

        InnerTest innerTest = new InnerTest();

        InnerTest.AA aa = new InnerTest.AA(1);
        InnerTest.AA bb = new InnerTest.AA(2);
        InnerTest.AA cc = new InnerTest.AA(1);

        List<InnerTest.AA> list = new ArrayList<>();
        list.add(aa);
        list.add(bb);
        list.add(cc);
        innerTest.setAaList(list);
        List<Integer> aaa = Arrays.asList(1, 2, 3, 4, 4, 4, 4, 3, 3, 3, 2);
        Set<Integer> collect = aaa.stream().collect(Collectors.toSet());
        List<InnerTest.AA> ll = innerTest.getAaList().stream().filter(aa1 -> aa.getCode().equals(2)).collect(Collectors.toList());

        Set<Integer> collect1 = list.stream().map(InnerTest.AA::getCode).collect(Collectors.toSet());
        System.out.println(collect1);
        System.out.println(collect);
        System.out.println(ll);


    }
}
